﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

using QuickTuner.Util;

namespace QuickTuner
{
    /// <summary>
    /// Store list of stations and provide logic to save/load from a stream.
    /// </summary>
    [Serializable]
    [XmlRoot("Stations")]
    public class StationList : List<Station>
    {
        // constructors _______________________________________________________

        /// <summary>
        /// Creates an empty StationList()
        /// </summary>
        public StationList() {}

        /// <summary>
        /// Creates a StationList and copy content from the specified StationList.
        /// </summary>
        /// <param name="source">Another StationList to copy content from.</param>
        public StationList(IEnumerable<Station> source)
            : base(source) {}

        // methods ____________________________________________________________

        /// <summary>
        /// Saves the StationList contents to the supplied stream.
        /// </summary>
        public void SaveXmlTo(Stream s)
        {
            this.XmlSerialize(s);
        }

        public void SaveBinaryTo(Stream s)
        {
            this.BinarySerialize(s);
        }

        /// <summary>
        /// Loads a StationList from the supplied stream.
        /// </summary>
        public static StationList LoadFrom(Stream s)
        {
            return s.DeserializeBinaryOrXml<StationList>();
        }
    }
}